home *** CD-ROM | disk | FTP | other *** search
- head 1.5;
- branch ;
- access ;
- symbols ;
- locks ; strict;
- comment @ * @;
-
-
- 1.5
- date 88.09.26.17.26.53; author douglis; state Exp;
- branches ;
- next 1.4;
-
- 1.4
- date 88.07.12.16.43.09; author douglis; state Exp;
- branches ;
- next 1.3;
-
- 1.3
- date 88.02.21.15.57.08; author douglis; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 87.09.15.16.04.18; author brent; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 87.08.24.10.21.56; author brent; state Exp;
- branches ;
- next ;
-
-
- desc
- @the sysStat program.
- @
-
-
- 1.5
- log
- @changed msgs for allow/refuse migration
- @
- text
- @/*
- * sysStat.c --
- *
- * Statistics generation for system calls and process migration.
- *
- * Copyright 1986, 1988 Regents of the University of California
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies. The University of California
- * makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without
- * express or implied warranty.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: sysStat.c,v 1.4 88/07/12 16:43:09 douglis Exp $ SPRITE (Berkeley)";
- #endif not lint
-
- #include "sprite.h"
- #include "fs.h"
- #include "sysStats.h"
- #include "mem.h"
- #include "byte.h"
- #include "cvt.h"
- #include "io.h"
- #include "option.h"
- #include "kernel/sysSysCall.h"
- #include "kernel/trace.h"
- #include "kernel/procMigrate.h"
-
- /*
- * Variables for options.
- */
-
- Boolean countCalls = FALSE;
- Boolean allowMigration = FALSE;
- Boolean refuseMigration = FALSE;
- Boolean getMigStatus = FALSE;
- Boolean doMigration = FALSE;
- Boolean startTrace = FALSE;
- Boolean stopTrace = FALSE;
- Boolean resetCount = FALSE;
- Boolean printVersion = FALSE;
- int debugLevel = -1;
- int numRecords = 200;
-
- Option optionArray[] = {
- {OPT_TRUE, 'c', (Address)&countCalls,
- "Print the number of system calls invoked."},
- {OPT_INT, 'd', (Address)&debugLevel,
- "Level to set proc_MigDebugLevel."},
- {OPT_TRUE, 'S', (Address)&getMigStatus,
- "Print whether process migration is allowed."},
- {OPT_TRUE, 'a', (Address)&allowMigration,
- "Allow future migrations to this machine (must be root)."},
- {OPT_TRUE, 'r', (Address)&refuseMigration,
- "Disallow future migrations to this machine (must be root)."},
- {OPT_TRUE, 'm', (Address)&doMigration,
- "Print process migration statistics."},
- {OPT_INT, 'n', (Address)&numRecords,
- "Number of process migration records to print."},
- {OPT_TRUE, 'R', (Address)&resetCount,
- "Reset the count of system calls to 0."},
- {OPT_TRUE, 't', (Address)&startTrace,
- "Enable tracing of process migration."},
- {OPT_TRUE, 'T', (Address)&stopTrace,
- "Disable tracing of process migration."},
- {OPT_TRUE, 'V', (Address)&printVersion,
- "Print compilation timestamp for the kernel."},
- };
- int numOptions = sizeof(optionArray) / sizeof(Option);
-
- /*
- * Constants used by tracing routines:
- * PROC_NUM_EVENTS - the number of valid trace events for proc.\
- */
-
- #define PROC_NUM_EVENTS 5
-
- /*
- * List of system calls to print out, corresponding to call number.
- * Whether or not they're local should be taken from some other
- * file in the kernel rather than repeated here....
- */
-
- typedef struct {
- char *name;
- Boolean local;
- } SysCallInfo;
-
- static SysCallInfo callArray[] = {
- "Proc_Fork", FALSE,
- "Proc_Exec", FALSE,
- "Proc_Exit", FALSE,
- "Sync_WaitTime", TRUE,
- "Test_PrintOut", TRUE,
- "Test_GetLine", TRUE,
- "Test_GetChar", TRUE,
- "Fs_OpenStub", TRUE,
- "Fs_ReadStub", TRUE,
- "Fs_WriteStub", TRUE,
- "Fs_UserClose", TRUE,
- "Fs_RemoveStub", TRUE,
- "Fs_RemoveDirStub", TRUE,
- "Fs_MakeDirStub", TRUE,
- "Fs_ChangeDirStub", TRUE,
- "Proc_Wait", FALSE,
- "Proc_Detach", FALSE,
- "Proc_GetIDs", FALSE,
- "Proc_SetIDs", FALSE,
- "Proc_GetGroupIDs", FALSE,
- "Proc_SetGroupIDs", FALSE,
- "Proc_GetFamilyID", FALSE,
- "Proc_SetFamilyID", FALSE,
- "Test_RpcStub", TRUE,
- "Test_StatsStub", TRUE,
- "Vm_CreateVA", TRUE,
- "Vm_DestroyVA", TRUE,
- "Sig_UserSend", FALSE,
- "Sig_Pause", TRUE,
- "Sig_SetHoldMask", TRUE,
- "Sig_SetAction", TRUE,
- "Prof_Start", TRUE,
- "Prof_End", TRUE,
- "Prof_DumpStub", FALSE,
- "Vm_Cmd", FALSE,
- "Sys_GetTimeOfDay", FALSE,
- "Sys_SetTimeOfDay", FALSE,
- "Sys_DoNothing", TRUE,
- "Proc_GetPCBInfo", FALSE,
- "Vm_GetSegInfo", TRUE,
- "Proc_GetResUsage", FALSE,
- "Proc_GetPriority", FALSE,
- "Proc_SetPriority", FALSE,
- "Proc_Debug", FALSE,
- "Proc_Profile", FALSE,
- "Fs_TruncateStub", TRUE,
- "Fs_TruncateIDStub", TRUE,
- "Fs_GetNewIDStub", TRUE,
- "Fs_GetAttributesStub", TRUE,
- "Fs_GetAttributesIDStub", TRUE,
- "Fs_SetAttributesStub", TRUE,
- "Fs_SetAttributesIDStub", TRUE,
- "Fs_SetDefPermStub", TRUE,
- "Fs_IOControlStub", TRUE,
- "Dev_VidEnable", FALSE,
- "Proc_SetEnviron", FALSE,
- "Proc_UnsetEnviron", FALSE,
- "Proc_GetEnvironVar", FALSE,
- "Proc_GetEnvironRange", FALSE,
- "Proc_InstallEnviron", FALSE,
- "Proc_CopyEnviron", FALSE,
- "Sync_SlowLockStub", TRUE,
- "Sync_SlowWaitStub", TRUE,
- "Sync_SlowBroadcastStub", TRUE,
- "Vm_PageSize", TRUE,
- "Fs_HardLinkStub", TRUE,
- "Fs_RenameStub", TRUE,
- "Fs_SymLinkStub", TRUE,
- "Fs_ReadLinkStub", TRUE,
- "Fs_CreatePipeStub", TRUE,
- "Vm_MapKernelIntoUser", FALSE,
- "Fs_AttachDiskStub", FALSE,
- "Fs_SelectStub", TRUE,
- "Sys_Shutdown", FALSE,
- "Proc_Migrate", FALSE,
- "Fs_MakeDeviceStub", TRUE,
- "Fs_CommandStub", FALSE,
- "Fs_LockStub", TRUE,
- "Sys_GetMachineInfo", TRUE,
- "Net_InstallRoute", FALSE,
- "Fs_ReadVector", TRUE,
- "Fs_WriteVector", TRUE,
- "Fs_CheckAccess", TRUE,
- "Proc_GetIntervalTimer", TRUE,
- "Proc_SetIntervalTimer", TRUE,
- "Fs_FileWriteBackStub", TRUE,
- "Proc_ExecEnv", TRUE,
- };
-
-
-
- /*
- *----------------------------------------------------------------------
- *
- * main --
- *
- * Driver.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Variable.
- *
- *----------------------------------------------------------------------
- */
-
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- ReturnStatus status = SUCCESS;
- char version[128];
- Boolean migStatus;
-
- Opt_Parse(&argc, argv, numOptions, optionArray);
- if (printVersion) {
- if (Sys_Stats(SYS_GET_VERSION_STRING, sizeof(version), version) ==
- SUCCESS){
- Io_Print("Kernel version: %s\n", version);
- Io_Flush(io_StdOut);
- }
- }
-
- if (debugLevel != -1) {
- status = Sys_Stats(SYS_PROC_MIGRATION, SYS_PROC_MIG_SET_DEBUG,
- (Address) &debugLevel);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "Sys_Stats (set debug level)");
- Proc_Exit(status);
- }
- }
-
- if (allowMigration || refuseMigration || getMigStatus) {
- status = Sys_Stats(SYS_PROC_MIGRATION, SYS_PROC_MIG_GET_STATUS,
- (Address) &migStatus);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "Sys_Stats (getting migration status)");
- Proc_Exit(status);
- }
-
- if (allowMigration) {
- status = Sys_Stats(SYS_PROC_MIGRATION, SYS_PROC_MIG_ALLOW,
- (Address) NULL);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "Sys_Stats (allow migration)");
- Proc_Exit(status);
- }
- Io_Print("Migration is currently allowed, previously %s.\n",
- migStatus ? "refused" : "allowed");
- } else if (refuseMigration) {
- status = Sys_Stats(SYS_PROC_MIGRATION, SYS_PROC_MIG_REFUSE,
- (Address) NULL);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "Sys_Stats (refuse migration)");
- Proc_Exit(status);
- }
- Io_Print("Migration is currently refused, previously %s.\n",
- migStatus ? "refused" : "allowed");
- } else {
- Io_Print("Migration is currently %s.\n",
- migStatus ? "refused" : "allowed");
- }
- }
- if (startTrace) {
- status = Sys_Stats(SYS_PROC_TRACE_STATS, SYS_PROC_TRACING_ON,
- (Address) NULL);
- if (status != SUCCESS) {
- Io_PrintStream(io_StdErr, "Error %x returned from Test_Stats.\n",
- status);
- Stat_PrintMsg(status, "");
- Proc_Exit(status);
- }
- }
-
- if (stopTrace) {
- status = Sys_Stats(SYS_PROC_TRACE_STATS, SYS_PROC_TRACING_OFF,
- (Address) NULL);
- if (status != SUCCESS) {
- Io_PrintStream(io_StdErr, "Error %x returned from Test_Stats.\n",
- status);
- Stat_PrintMsg(status, "");
- Proc_Exit(status);
- }
- }
-
- if (doMigration) {
- status = PrintMigration();
- }
-
- if (countCalls) {
- status = PrintNumCalls();
- }
-
- if (resetCount) {
- status = Sys_Stats(SYS_SYS_CALL_STATS, 0, (Address) NULL);
- }
-
- Proc_Exit(status);
- }
-
-
- /*
- *----------------------------------------------------------------------
- *
- * PrintMigration --
- *
- * Print the most recent process migration trace records.
- *
- * Results:
- * The return status from Test_Stats is returned.
- *
- * Side effects:
- * Trace records are written to io_StdOut.
- *
- *----------------------------------------------------------------------
- */
-
-
- ReturnStatus
- PrintMigration()
- {
- int index; /* index of current table entry */
- Time baseTime, deltaTime, startTime; /* Times for print out */
- Address buffer; /* Buffer for trace records */
- int numRecs; /* number of records actually copied */
- Trace_Record *traceArray;
- Proc_TraceRecord *procTraceArray;
- register Trace_Record *tracePtr;
- register Proc_TraceRecord *procTracePtr;
- ReturnStatus status;
- static char *flagsArray[] = {"RE", "RS", "HE", "HS", " "};
- static char *eventArray[] = {"start", "end", "xfer", "call", "migtrap"};
- static char *commandArray[] = {"proc", "vm", "files", "stream", "user",
- "resume"};
- /*
- * Get a copy of the trace table.
- */
-
- buffer = Mem_Alloc(sizeof(int) + numRecords *
- (sizeof(Trace_Record) + sizeof(Proc_TraceRecord)));
- status = Sys_Stats(SYS_PROC_TRACE_STATS, numRecords, buffer);
- if (status != SUCCESS) {
- Io_PrintStream(io_StdErr, "Error from Test_Stats.\n");
- Stat_PrintMsg(status, "");
- return(status);
- }
-
- Byte_EmptyBuffer(buffer, int, numRecs);
- Io_PrintStream(io_StdErr, "Number of records is %d.\n", numRecs);
- Io_Flush(io_StdErr);
- if (numRecs == 0) {
- return;
- }
-
- traceArray = (Trace_Record *) buffer;
- procTraceArray = (Proc_TraceRecord *) (buffer + numRecs *
- sizeof(Trace_Record));
-
-
- Io_Print("\n");
- #define PRINT_MIGHEADER() \
- Io_Print("%10s %10s %10s %2s %10s %24s %7s\n", \
- "Time", "Delta", "ProcessID", "HR", "Event", "Call", "Sta")
- PRINT_MIGHEADER();
-
- baseTime = traceArray[0].time;
- startTime = traceArray[0].time;
-
- for (index = 0; index < numRecs; index++) {
- tracePtr = &traceArray[index];
- procTracePtr = &procTraceArray[index];
-
- Time_Subtract(tracePtr->time, startTime, &deltaTime);
- Io_Print(" %3d.%06d",
- deltaTime.seconds,
- deltaTime.microseconds);
- Time_Subtract(tracePtr->time, baseTime, &deltaTime);
- Io_Print(" %3d.%06d",
- deltaTime.seconds,
- deltaTime.microseconds);
- baseTime = tracePtr->time;
-
- if (tracePtr->flags & TRACE_DATA_INVALID) {
- procTracePtr->flags = 4;
- procTracePtr->processID = (Proc_PID) NULL;
- }
- if (((unsigned) procTracePtr->flags) > 3 ||
- ((unsigned) tracePtr->event) >= PROC_NUM_EVENTS) {
- Io_PrintStream(io_StdErr,
- "Entry %d: invalid flags (%d) or event (%d).\n",
- index, procTracePtr->flags, tracePtr->event);
- return(FAILURE);
- }
-
- Io_Print("%10x %3s %10s", procTracePtr->processID,
- flagsArray[procTracePtr->flags],
- eventArray[tracePtr->event]);
-
- if (tracePtr->event == PROC_MIGTRACE_TRANSFER) {
- Io_Print(" %-10s",
- commandArray[(int) procTracePtr->info.command.type]);
- if (procTracePtr->info.command.data != (ClientData) NIL) {
- Io_Print(" %20d",
- procTracePtr->info.command.data);
- }
- } else if (tracePtr->event == PROC_MIGTRACE_CALL) {
- Io_Print(" %24s",
- callArray[(int) procTracePtr->info.call.callNumber].name);
- if (!(procTracePtr->flags & PROC_MIGTRACE_START)) {
- Io_Print(" %10x",
- procTracePtr->info.call.status);
- }
- }
-
- Io_Print("\n");
- }
- PRINT_MIGHEADER();
- return(SUCCESS);
- }
-
-
- /*
- *----------------------------------------------------------------------
- *
- * PrintNumCalls --
- *
- * Print the number of system calls invoked by processes since the last
- * time the counter was reset.
- *
- * Results:
- * The return status from Test_Stats is returned.
- *
- * Side effects:
- * The number of calls is output.
- *
- *----------------------------------------------------------------------
- */
-
-
- ReturnStatus
- PrintNumCalls()
- {
- Address buffer; /* Buffer to hold counters */
- ReturnStatus status;
- int i;
- int numForeign = 0;
- int numLocal = 0;
- register int *numCalls;
- int numAlloc;
-
- /*
- * Get a copy of the array of counters.
- */
-
- numAlloc = sizeof(callArray) / sizeof(SysCallInfo);
- buffer = Mem_Alloc(numAlloc * sizeof(int));
- status = Sys_Stats(SYS_SYS_CALL_STATS, numAlloc, buffer);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "Error from Test_Stats");
- return(status);
- }
- numCalls = (int *) buffer;
-
- for (i = 0; i < numAlloc; i++) {
- Io_Print("%d\t%-30s", numCalls[i], callArray[i].name);
- if (callArray[i].local) {
- numLocal += numCalls[i];
- Io_Print("local\n");
- } else {
- numForeign += numCalls[i];
- Io_Print("remote\n");
- }
- }
- Io_Print("\n\nTotal number of calls: %d local, %d remote.\n",
- numLocal, numForeign);
- Io_Print("%d/%d = %6.2f%% remote.\n",
- numForeign, numForeign + numLocal,
- ((double) numForeign) / (numForeign + numLocal));
- return(SUCCESS);
- }
- @
-
-
- 1.4
- log
- @added ability to set and obtain migration status (allowed/refused),
- and changed to use modified option to Sys_Stats. Removed default
- that made printing migration trace records take place if no other
- options were specified, 'cause that's dumb.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: sysStat.c,v 1.3 88/02/21 15:57:08 douglis Exp $ SPRITE (Berkeley)";
- d207 1
- a217 9
- /*
- * If we're doing an "allowMigration" or "refuseMigration" then
- * get the status after we do it and print out "migration
- * is currently ..."
- */
- if (allowMigration || refuseMigration) {
- getMigStatus = TRUE;
- }
-
- d227 1
- a227 21
- if (allowMigration) {
- status = Sys_Stats(SYS_PROC_MIGRATION, SYS_PROC_MIG_ALLOW,
- (Address) NULL);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "Sys_Stats (allow migration)");
- Proc_Exit(status);
- }
- }
-
- if (refuseMigration) {
- status = Sys_Stats(SYS_PROC_MIGRATION, SYS_PROC_MIG_REFUSE,
- (Address) NULL);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "Sys_Stats (refuse migration)");
- Proc_Exit(status);
- }
- }
-
- if (getMigStatus) {
- Boolean migStatus;
-
- d234 23
- a256 2
- Io_Print("Migration is currently %s.\n",
- migStatus ? "refused" : "allowed");
- a257 1
-
- @
-
-
- 1.3
- log
- @Changed the sense of some of the calls (local/remote). [This change
- is OLD!] Changed the notion of # of calls to use sizeof. Print
- summary line.
- @
- text
- @d6 8
- a13 2
- * Copyright 1986 Regents of the University of California
- * All rights reserved.
- d17 1
- a17 1
- static char rcsid[] = "$Header: sysStat.c,v 1.2 87/09/15 16:04:18 brent Exp $ SPRITE (Berkeley)";
- d37 3
- d53 6
- d60 1
- a60 1
- "Print process migration statistics (DEFAULT)."},
- d70 1
- a70 1
- "Print compilation timestamp."},
- d83 2
- d178 2
- d206 1
- d210 5
- a214 2
- Io_Print("System Stats: %s\n", Version());
- Io_Flush(io_StdOut);
- d217 7
- a223 3
- if (!(countCalls || startTrace || stopTrace || resetCount)
- && (debugLevel == -1)) {
- doMigration = TRUE;
- d227 2
- a228 5
- /*
- * Call Test_Stats with a negative value as an argument to indicate
- * debug level rather than # of records.
- */
- status = Sys_Stats(SYS_PROC_TRACE_STATS, -debugLevel, (Address) NULL);
- d230 1
- a230 3
- Io_PrintStream(io_StdErr, "Error %x returned from Test_Stats.\n",
- status);
- Stat_PrintMsg(status, "");
- d233 31
- @
-
-
- 1.2
- log
- @Changed around some names (Sys_Stats, etc.) --- ci by FD
- @
- text
- @d11 1
- a11 1
- static char rcsid[] = "$Header: sysStat.c,v 1.1 87/08/24 10:21:56 brent Exp $ SPRITE (Berkeley)";
- d83 1
- a83 1
- "Fs_OpenStub", FALSE,
- d87 4
- a90 4
- "Fs_RemoveStub", FALSE,
- "Fs_RemoveDirStub", FALSE,
- "Fs_MakeDirStub", FALSE,
- "Fs_ChangeDirStub", FALSE,
- d121 1
- a121 1
- "Fs_TruncateStub", FALSE,
- d124 1
- a124 1
- "Fs_GetAttributesStub", FALSE,
- d126 1
- a126 1
- "Fs_SetAttributesStub", FALSE,
- d128 1
- a128 1
- "Fs_SetDefPermStub", FALSE,
- d141 4
- a144 4
- "Fs_HardLinkStub", FALSE,
- "Fs_RenameStub", FALSE,
- "Fs_SymLinkStub", FALSE,
- "Fs_ReadLinkStub", FALSE,
- d151 1
- a151 1
- "Fs_MakeDeviceStub", FALSE,
- d153 1
- a153 1
- "Fs_LockStub", FALSE,
- d155 6
- d398 1
- d404 3
- a406 2
- buffer = Mem_Alloc(SYS_NUM_SYSCALLS * sizeof(int));
- status = Sys_Stats(SYS_SYS_CALL_STATS, SYS_NUM_SYSCALLS, buffer);
- d413 1
- a413 1
- for (i = 0; i < SYS_NUM_SYSCALLS; i++) {
- d425 3
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d11 1
- a11 1
- static char rcsid[] = "$Header: proto.c,v 1.5 86/09/18 06:35:57 ouster Exp $ SPRITE (Berkeley)";
- d16 1
- a16 1
- #include "rpc.h"
- d198 1
- a198 1
- status = Test_Stats(PROC_TRACE_STATS, -debugLevel, (Address) NULL);
- d208 2
- a209 1
- status = Test_Stats(PROC_TRACE_STATS, PROC_TRACING_ON, (Address) NULL);
- d219 2
- a220 1
- status = Test_Stats(PROC_TRACE_STATS, PROC_TRACING_OFF, (Address) NULL);
- d238 1
- a238 1
- status = Test_Stats(SYS_CALL_STATS, 0, (Address) NULL);
- d284 1
- a284 2
- status = Test_Stats(PROC_TRACE_STATS, numRecords,
- buffer);
- d398 1
- a398 1
- status = Test_Stats(SYS_CALL_STATS, SYS_NUM_SYSCALLS, buffer);
- @
-